package util
{
	
	/**
	 * Utility class for doing math not found in Math
	 */
	public class MyMath
	{
		/** Pi times two */
		public static const TWO_PI:Number = Math.PI * 2;
		
		/**
		 * Returns the sign of the number
		 * @return	-1, 1 or 0
		 */
		public static function sign(n:Number):int
		{
			if (n < 0)
				return -1;
			if (n > 0)
				return 1;
			return 0;
		}
		
		/**
		 * Returns the smaller of two values.
		 * @param	a
		 * @param	b
		 * @return	a if a less than b, else b
		 */
		public static function min2(a:Number, b:Number):Number
		{
			return (a < b) ? a : b;
		}
		
		/**
		 * Returns the larger of two values.
		 * @param	a
		 * @param	b
		 * @return	a if a > b, else b
		 */
		public static function max2(a:Number, b:Number):Number
		{
			return (a > b) ? a : b;
		}
		
		/**
		 * Returns true if angles a less than n less than b when normalized, else returns false.
		 * @param	n	angle to check
		 * @param	a	min angle
		 * @param	b	max angle
		 * @return
		 */
		public static function angleIsBetween(n:Number, a:Number, b:Number):Boolean
		{
			n = (TWO_PI + (n % TWO_PI)) % TWO_PI;
			a = (TWO_PI + (a % TWO_PI)) % TWO_PI;
			b = (TWO_PI + (b % TWO_PI)) % TWO_PI;
			
			if (a < b)
				return a <= n && n <= b;
			return a <= n || n <= b;
		}
		
		/**
		 * Convert radians to degrees.
		 * @param	r
		 * @return
		 */
		static public function degrees(r:Number):Number
		{
			return r * 180 / Math.PI;
		}
		
		/**
		 * Calculate a logarithm with an arbitrary base.
		 * @param	val
		 * @param	base
		 * @return
		 */
		static public function log(val:Number, base:Number):Number
		{
			return Math.log(val) / Math.log(base);
		}
	}
}